<?php
	App::import("Model","Config.BaseConfig");
	
	class GeoCoderAccess extends BaseConfig
	{
		var $name = "GeoCoderAccess";
		
		function setAccessInfo(GeoCoder $GeoCoder,$firstCall,$ok)
		{
			$lastAccessInfo = $this->getAccessInfo($GeoCoder);
			$today = gmdate('U');
			$firstCallTime = $lastAccessInfo['firstCall'];
			//refresh couters if it's a new i
			if($firstCall)
			{
				$count = 1;
				$firstCallTime = $today;
			}else{
				$count = $lastAccessInfo['requestCount']+1;
			}			
			$data[$this->alias][$GeoCoder->getName()] = array('requestCount'=>$count,'firstCall'=>$firstCallTime,'lastCall'=>$today,'ok'=>(int)$ok);
			$this->save($data);
		}
		
		function getAccessInfo(GeoCoder $GeoCoder)
		{
			$this->init();
			$default = array("lastCall"=>null,"ok"=>false,'firstCall'=>false,'requestCount'=>0);
			$name = $GeoCoder->getName();
			$info =  cr("GeoCoderAccess.$name");
			$info = am($default,$info);
			return $info;
		}
	}
?>